package edu.suda.LoopCodePlus.service.impl;

import edu.suda.LoopCodePlus.entity.Problem;
import edu.suda.LoopCodePlus.mapper.ProblemMapper;
import edu.suda.LoopCodePlus.mapper.TestCaseMapper;
import edu.suda.LoopCodePlus.service.ProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProblemServiceImpl implements ProblemService {
    @Autowired
    private ProblemMapper problemMapper;
    @Autowired
    private TestCaseMapper testCaseMapper;
    /** 依据标签，数据集，和状态筛查题目*/
    @Override
    public List<Problem> findPublicAll(String tag,String collection,Integer status){
        return problemMapper.select_AllPublicProblem(tag,collection,status);
    }
    @Override
    public List<Problem> findAllByTag(String tag){
        return problemMapper.select_problemByTag(tag);
    }
    @Override
    public List<Problem> findAllByCollection(String collection){
        return problemMapper.select_problemByCollection(collection);
    }
    @Override
    public Problem findProblemById(Integer problemId){
        return problemMapper.select_problemById(problemId);
    }

    @Override
    public Problem findProblemTestCase(Integer problemId){
        return problemMapper.select_problemById(problemId);
    }
    @Override
    public boolean addProblem(Problem problem){
        try{
            problemMapper.insert_problem(problem);
            return true;
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
    }
    @Override
    public List<Problem> findAllByUserId(Integer userId){
        return problemMapper.select_problemByUserId(userId);
    }
    @Override
    public boolean deleteProblemById(Integer problemId,Integer userId){
        try{
            problemMapper.update_problemUserIdAndStatus(problemId,userId);
            return true;
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
    }
    @Override
    public boolean updateProblemById(Integer problemId,Integer userId,Problem problem){
        try{
            problemMapper.update_problemById(problemId,userId,problem);
            return true;
        }catch (Exception e){
            System.out.println(e.getMessage());
            return false;
        }
    }
}
